package cn.kent.middle;

/**
 * 1456. 定长子串中元音的最大数目
 */
public class MaxVowels {
    public static void main(String[] args) {
        System.out.println("hello".substring(0, 2));
        MaxVowels maxVowels = new MaxVowels();
        int leecode = maxVowels.maxVowels("abciiidef", 3);
        System.out.println(leecode);
    }

    private char[] matchArr = {'a', 'e', 'i', 'o', 'u'};

    /**
     * 滑动窗口
     */
    public int maxVowels(String s, int k) {
        int n = s.length();
        int l = 0, r = l + k - 1, max = 0;
        for (int i = 0; i < k; i++) {
            max += match(s.charAt(i));
        }
        int ans = max;
        for (int i = k; i < n; i++) {
            max += match(s.charAt(i)) - match(s.charAt(i - k));
            ans = Math.max(ans, max);
        }
        return ans;
    }


    private int match(char mathchChar) {
        if (mathchChar == 'a' || mathchChar == 'e' || mathchChar == 'i' || mathchChar == 'o' || mathchChar == 'u') return 1;
        return 0;
    }
}
